import React from 'react';
import Route from 'react-router/lib/Route';
import { IndexRedirect } from 'react-router';
import { WeaErrorPage, WeaLocaleProvider, WeaTools } from 'ecCom';
import Home from './components/Home';
import Add from './components/Add';
import Monitor from './components/Monitor';
import Center from './components/Center';
import Count from './components/Count';
import DocOfAuthor from './components/DocOfAuthor';
import DocOfDepartment from './components/DocOfDepartment';
import DocOfSubDepartment from './components/DocOfSubDepartment';
import Catalog from './components/Catalog';
import Search from './components/Search';
import Move from './components/Move';
import Dummy from './components/Dummy';
import Share from './components/Share';
import DocRecycle from './components/DocRecycle';
import Subscribe from './components/Subscribe';
import News from './components/news/index';
import More from './components/More';
import NetDisk from './components/netdisk';
// import Edit from './components/Edit';
import KnowledgeEdit from './components/knowledge/KnowledgeEdit.js';
import KnowledgeList from './components/knowledge/KnowledgeList.js';
import KnowledgeMapList from './components/knowledgeMap/KnowledgeMapList.js';

import './style';
import './util';

import stores from './stores';
import NewsContent from './components/news/newsContent';

const getLocaleLabel = WeaLocaleProvider.getLocaleLabel.bind(this, 'document');
const getLabel = WeaLocaleProvider.getLabel;
class Error extends React.Component {
  render() {
    return (
      <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@9zjv4v`} msg={getLabel('384713', '对不起，无法找到该页面！')} />
    );
  }
}

const onEnter = (nextState, replace, callback) => {
    WeaTools.checkSSO('', false).then(() => {
        getLocaleLabel(nextState, replace, callback);
    });
};

const onEnter2 = (nextState, replace, callback) => {
	if (location.href.indexOf('outDoc=1') != -1) {
		callback();
		return;
	}
	onEnter(nextState, replace, callback);
};

const Routes = (
  <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@ffzuu6`} path="document" component={Home}>
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@auhltz`} name="add" path="add" onEnter={onEnter} component={Add} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@h64bb2`} name="center" path="center" onEnter={onEnter} component={Center} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@0dkooq`} name="count" path="count" onEnter={onEnter} component={Count} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@bk2k13`} name="catalog" path="catalog" onEnter={onEnter} component={Catalog} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@6ssznz`} name="docofauthor" path="docofauthor" onEnter={onEnter} component={DocOfAuthor} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@e41dwk`} name="docofdepartment" path="docofdepartment" onEnter={onEnter} component={DocOfDepartment} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@sfxie5`} name="docofsubdepartment" path="docofsubdepartment" onEnter={onEnter} component={DocOfSubDepartment} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@l1a67e`} name="monitor" path="monitor"onEnter={onEnter} component={Monitor} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@ecksyz`} name="dummy" path="dummy" onEnter={onEnter} component={Dummy} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@gamqtl`} name="search" path="search" onEnter={onEnter} component={Search} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@96kp6b`} name="move" path="move" onEnter={onEnter} component={Move} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@qzwk9k`} name="share" path="share" onEnter={onEnter} component={Share} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@rxy3v7`} name="docRecycle" path="docRecycle" onEnter={onEnter} component={DocRecycle} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@oo6hlz`} name="subscribe" path="subscribe" onEnter={onEnter} component={Subscribe} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@kmvb7p`} name="news" path="news" onEnter={onEnter} component={News} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@m5jhy0`} name="more" path="more" onEnter={onEnter2} component={More} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@ev3u22`} name="KnowledgeEdit" breadcrumbName="知识点编辑" path="knowledgeEdit" component={KnowledgeEdit} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@xeifve`} name="KnowledgeList" breadcrumbName="知识点维护" path="knowledgeList" component={KnowledgeList} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@cbxwl5`} name="KnowledgeMapList" breadcrumbName="知识地图维护" path="KnowledgeMapList" component={KnowledgeMapList} />
	<Route ecId={`${this && this.props && this.props.ecId || ''}_Route@1cgkt6`} name="netdisk" path="netdisk" onEnter={onEnter} component={NetDisk} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@3gft83`} path="*" component={Error} />
  </Route>
);

const KnowledgeEditCom = props => <KnowledgeEdit ecId={`${this && this.props && this.props.ecId || ''}_KnowledgeEdit@lnc8ox`} {...props} key="KnowledgeEdit" />;

module.exports = {
  Route: Routes,
  store: stores,
  com: {
    News,
  },
  KnowledgeEditCom,
};
